home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17073 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: user1.mnsinc.com!huang
  2. From: huang@mnsinc.com (Szu-Wen Huang)
  3. Newsgroups: comp.lang.c++,comp.lang.c,comp.os.ms-windows.programmer.misc
  4. Subject: Re: fastest code
  5. Followup-To: comp.lang.c++,comp.lang.c,comp.os.ms-windows.programmer.misc
  6. Date: 13 Apr 1996 14:54:06 GMT
  7. Organization: Monumental Network Systems
  8. Message-ID: <4kof6e$te@news1.mnsinc.com>
  9. References: <316112A2.7D37@public.sta.net.cn> <4kgu7g$n9a@solutions.solon.com> <4kh2p7INNkcq@keats.ugrad.cs.ubc.ca> <4kjdus$fiq@samba.rahul.net> <4kjpn0INN817@keats.ugrad.cs.ubc.ca> <829352535snz@genesis.demon.co.uk>
  10. NNTP-Posting-Host: user1.mnsinc.com
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
  14.  
  15. : Not to mention that the gcc version of that compiled code, in addition to
  16. : working, looks better optimised. What I did find curious was that on
  17. : the compilers I tried:
  18.  
  19. :     prom[i] = prom[i+i];
  20.  
  21. : produces different code to:
  22.  
  23. :     prom[i] = prom[2*i];
  24.  
  25. : where the code for the latter certainly looks more efficient (although
  26. : it is difficult to guess the exact instruction timings). I wonder if
  27. : Watcom compiles the 2nd version correctly.
  28.  
  29. Why do you say the latter looks more efficient?  A naive compiler would
  30. perform an addition with the former and a multiplication with the latter.
  31. One would almost always expect addition to be faster than multiplication.
  32. An optimizing compiler might be able to realize they are actually the
  33. same, and perhaps even decide to implement both as bitwise shifts.  In
  34. any case, I wouldn't expect the former to be slower than the latter.  (It
  35. certainly *might* be, but chances are slim).
  36.